package com.cloudshadow.platform.server.demo.controller;

import com.cloudshadow.platform.server.common.base.controller.BaseController;
import com.cloudshadow.platform.server.common.base.model.PageModel;
import com.cloudshadow.platform.server.common.base.utils.VoUtil;
import com.cloudshadow.platform.server.common.base.vo.BasicVo;
import com.cloudshadow.platform.server.demo.annotation.NoLogin;
import com.cloudshadow.platform.server.demo.model.DemoModel;
import com.cloudshadow.platform.server.demo.req.DemoAddReq;
import com.cloudshadow.platform.server.demo.req.DemoSearchReq;
import com.cloudshadow.platform.server.demo.service.DemoService;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import org.springframework.web.bind.annotation.*;

/**
 * Created by apple on 17/3/3.
 */

@RestController
@RequestMapping("demo")
public class DemoController extends BaseController<DemoService, DemoModel>{


    @NoLogin
    @HystrixCommand(fallbackMethod="getFallback")
    public BasicVo<DemoModel> findAll(@RequestBody DemoSearchReq searchReq){
        return VoUtil.setSuccessResult(
                new PageModel(
                        getPage(searchReq)
                )

        );
    }


//    @HystrixCommand(fallbackMethod="getFallback")
    @NoLogin
    public BasicVo<DemoModel> findOne(@RequestParam String id){
//        server.save(changeEntity(new DemoAddReq()));
//        server.delete(id);
        return VoUtil.setSuccessResult(server.findOneByID(id));
    }

    @NoLogin
    public BasicVo<DemoModel> save(@RequestBody DemoAddReq saveReq){
        return VoUtil.setSuccessResult(
                server.save(
                        changeEntity(saveReq)
                )
        );
    }

    public BasicVo<DemoModel> del(@RequestParam String id){
        server.delete(id);
        return VoUtil.setSuccessResult();
    }

}
